package br.com.massai.model.entity;

import java.math.BigDecimal;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.envers.Audited;

@Entity
@Audited
@Table(name = "GROUP_ITEM")
@NamedQueries({
	@NamedQuery(name = "GroupItem.find", query = "SELECT g FROM GroupItem g"),
	@NamedQuery(name = "GroupItem.duplicate", query = "SELECT COUNT(g) FROM GroupItem g WHERE g.productionGroup =:productionGroup AND g.serviceItem =:serviceItem")
})
public class GroupItem extends GenericEntity {

	private static final long serialVersionUID = -1747166580363814952L;

	@Id
	@SequenceGenerator(name = "seqGroupItem", sequenceName = "seq_group_item", allocationSize = 1)
	@GeneratedValue(generator = "seqGroupItem", strategy = GenerationType.SEQUENCE)
	private Long id;

	@Column(name = "UNIT_VALUE", nullable = false, precision = 10, scale = 2, columnDefinition = "NUMERIC(10,2) DEFAULT 0")
	private BigDecimal unitValue;

	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "PRODUCTION_GROUP_ID", referencedColumnName = "ID")
	private ProductionGroup productionGroup;
	
	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "SERVICE_ITEM_ID", referencedColumnName = "ID")
	private ServiceItem serviceItem;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public BigDecimal getUnitValue() {
		return unitValue;
	}

	public void setUnitValue(BigDecimal unitValue) {
		this.unitValue = unitValue;
	}

	public ProductionGroup getProductionGroup() {
		return productionGroup;
	}

	public void setProductionGroup(ProductionGroup productionGroup) {
		this.productionGroup = productionGroup;
	}

	public ServiceItem getServiceItem() {
		return serviceItem;
	}

	public void setServiceItem(ServiceItem serviceItem) {
		this.serviceItem = serviceItem;
	}

}
